/**
 * Created by james on 2017/10/24.
 */
'use strict';
import React, {Component} from 'react';
import LoginScreen               from '../src/js/screen/LoginScreen'
import ShopScreen                from '../src/js/screen/ShopScreen'
import Main                      from '../src/js/screen/MainScreen'

export const SCENE_ENUM: Object = {

    SCENE_SHOPSCREEN:{
        id:"ShopScreen",
        c:ShopScreen
    },
    SCENE_LOGINSCREEN:{
        id:"LoginScreen",
        c:LoginScreen
    },
    SCENE_MAIN:{
        id:"Main",
        c:Main
    },
};

//顶层景数组 所有调用toRootScene跳转的都放这里
let SCENE_ARR: Array = [];

let SCENE_DIC: Object = {};

export default class UIManager {

    static init() {
        var key: string;
        var route: Object;


        for (key in SCENE_ENUM) {
            console.log('数组---',SCENE_ENUM)
            route = {id: SCENE_ENUM[key].id};
            SCENE_DIC[route.id] = route;
            SCENE_ARR.push(route);
        }
    }


    /*
     *  获取顶层场景
     *  参数举例{id:UIManager.SCENE_LOGIN}
     *  可追加自定义参数{id:UIManager.SCENE_LOGIN,自定义参数名1:自定义参数1,自定义参数名2:自定义参数2,...}
     */
    static getScene(params: Object): Object {

        var route: Object = SCENE_DIC[params.id];
        var key: string;
        if (route) {
            for (key in route) {
                if (key !== "id" && key !== "sceneConfig") {
                    delete route[key];
                }
            }
        }
        if (params) {
            for (key in params) {
                if (key !== "id") route[key] = params[key];
            }
        }
        return route;
    }

    /*
     *  跳转到顶层的一个场景
     *  参数举例{id:UIManager.SCENE_LOGIN}
     *  可追加自定义参数{id:UIManager.SCENE_LOGIN,自定义参数名1:自定义参数1,自定义参数名2:自定义参数2,...}
     *  传"pop"返回上一个场景
     */
    static toRootScene(route: Object) {
        var targetRoute: Object;
        if (route !== "back") {
            targetRoute = UIManager.getScene(route);
        } else {
            targetRoute = route;
        }
        console.log('target==================',targetRoute);
        // DeviceEventEmitter.emit(UIEvents.TO_ROOT_SCENE, targetRoute);
    }


}
